﻿using System;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using RefLib.MVC.Util;

namespace RefLib.MVC
{
    public static class jqViewModelExtension
    {
        public static MvcHtmlString jqModel(this HtmlHelper helper, string modelName, object model)
        {
            var sb = new ScriptBuilder();
            string script = new JavaScriptSerializer().Serialize(model);
            sb.AddLine(String.Format("var {0} = {1};", modelName, script));
            return new MvcHtmlString(sb.GetScriptBlock());
        }
    }
}
